package cn.jja8.config.tool.work.basic;

import java.util.HashMap;
import java.util.Map;

/**
 * 管理基础数据类型
 * */
public class BasicFieldHandManager {
    final Map<Class, BasicFieldHand> fieldAsMap = new HashMap<>();
    public BasicFieldHandManager() {
        add(new FieldHandBoolean());
        add(new FieldHandByte());
        add(new FieldHandDouble());
        add(new FieldHandFloat());
        add(new FieldHandInt());
        add(new FieldHandLong());
        add(new FieldHandShort());
        add(new FieldHandChar());
    }
    public void add(BasicFieldHand basicFieldHand){
        fieldAsMap.put(basicFieldHand.Type(), basicFieldHand);
    }

    public BasicFieldHand get(Class type){
        return fieldAsMap.get(type);
    }

    public <T> BasicFieldHand getNoNull(Class<T> type){
        BasicFieldHand basicFieldHand = fieldAsMap.get(type);
        if (basicFieldHand==null){
            throw new Error("没有找到合适的用于"+type+"的BasicFieldHand");
        }
        return basicFieldHand;
    }

}
